{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}

function foo(n:integer):boolean;
var
	r:boolean=false;
begin
	if n<=99 then
	begin
		if n=11 then r:=true;
	end else if n<=999 then
	begin
		if (n mod 10) = (n div 100) then r:=true;
	end else
	begin
		if ((n mod 10) = (n div 1000)) and ((n div 10 mod 10) = (n div 100 mod 10)) then r:=true;
	end;
	foo:=r;
end;

var
	a:array[1..2000] of boolean;
	i,j:integer;
begin
	for i:=2 to 2000 do
		a[i]:=true;
	for i:=2 to 45 do
	begin
		if a[i] then
		begin
			j:=2*i;
			while(j<=2000)do
			begin
				a[j]:=false;
				j:=j+i;
			end;
		end;
	end;
	readln(j);
	for i:=10 to j do
		if a[i] and foo(i) then writeln(i);
end.
